package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppRankTeam;
import com.ruoyi.background.service.IAppRankTeamService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 队伍排行榜Controller
 *
 * @author susu
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/applet/teamRank")
public class AppRankTeamController extends BaseController {
    @Autowired
    private IAppRankTeamService appRankTeamService;

    /**
     * 查询队伍排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppRankTeam appRankTeam) {
        startPage();
        List<AppRankTeam> list = appRankTeamService.selectAppRankTeamList(appRankTeam);
        return getDataTable(list);
    }

    /**
     * 导出队伍排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:export')")
    @Log(title = "队伍排行榜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppRankTeam appRankTeam) {
        List<AppRankTeam> list = appRankTeamService.selectAppRankTeamList(appRankTeam);
        ExcelUtil<AppRankTeam> util = new ExcelUtil<AppRankTeam>(AppRankTeam.class);
        util.exportExcel(response, list, "队伍排行榜数据");
    }

    /**
     * 获取队伍排行榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appRankTeamService.selectAppRankTeamById(id));
    }

    /**
     * 新增队伍排行榜
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:add')")
    @Log(title = "队伍排行榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppRankTeam appRankTeam) {
        return toAjax(appRankTeamService.insertAppRankTeam(appRankTeam));
    }

    /**
     * 修改队伍排行榜
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:edit')")
    @Log(title = "队伍排行榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppRankTeam appRankTeam) {
        return toAjax(appRankTeamService.updateAppRankTeam(appRankTeam));
    }

    /**
     * 删除队伍排行榜
     */
    @PreAuthorize("@ss.hasPermi('applet:teamRank:remove')")
    @Log(title = "队伍排行榜", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appRankTeamService.deleteAppRankTeamByIds(ids));
    }
}
